/**
 * Copyright 2010 upTick Pty Ltd
 *
 * Licensed under the terms of the GNU Lesser General Public License version 3 
 * as published by the Free Software Foundation. You may obtain a copy of the
 * License at: http://www.gnu.org/copyleft/lesser.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations 
 * under the License. 
 */

package au.com.uptick.serendipity.client.gin;

import au.com.uptick.serendipity.client.NameTokens;
import au.com.uptick.serendipity.client.SerendipityPlaceManager;
import au.com.uptick.serendipity.client.presenter.*;
import au.com.uptick.serendipity.client.resourcecentre.presenter.HighlightsPresenter;
import au.com.uptick.serendipity.client.resourcecentre.view.HighlightsView;
import au.com.uptick.serendipity.client.sales.presenter.AccountsPresenter;
import au.com.uptick.serendipity.client.sales.presenter.ActivitiesPresenter;
import au.com.uptick.serendipity.client.sales.presenter.CalendarPresenter;
import au.com.uptick.serendipity.client.sales.view.AccountsView;
import au.com.uptick.serendipity.client.sales.view.ActivitiesView;
import au.com.uptick.serendipity.client.sales.view.CalendarView;
import au.com.uptick.serendipity.client.settings.presenter.AdministrationPresenter;
import au.com.uptick.serendipity.client.settings.view.AdministrationView;
import au.com.uptick.serendipity.client.view.*;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.inject.Singleton;
import com.gwtplatform.mvp.client.RootPresenter;
import com.gwtplatform.mvp.client.gin.AbstractPresenterModule;
import com.gwtplatform.mvp.client.proxy.ParameterTokenFormatter;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.TokenFormatter;

public class ClientModule extends AbstractPresenterModule {

    @Override
    protected void configure() {
        bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
        bind(PlaceManager.class).to(SerendipityPlaceManager.class).in(Singleton.class);
        bind(TokenFormatter.class).to(ParameterTokenFormatter.class).in(Singleton.class);
        bind(RootPresenter.class).asEagerSingleton();
//    bind(ProxyFailureHandler.class).to(DefaultProxyFailureHandler.class).in(        Singleton.class);

        // Constants
        bindConstant().annotatedWith(DefaultPlace.class).to(NameTokens.signInPage);

        // Sign In
        bindPresenter(SignInPagePresenter.class, SignInPagePresenter.MyView.class,
                      SignInPageView.class, SignInPagePresenter.MyProxy.class);

        // Main Pages
        bindPresenter(MainPagePresenter.class, MainPagePresenter.MyView.class,
                      MainPageView.class, MainPagePresenter.MyProxy.class);
        bindPresenter(MainPageSmartGwtPresenter.class, MainPageSmartGwtPresenter.MyView.class,
                      MainPageSmartGwtView.class, MainPageSmartGwtPresenter.MyProxy.class);
        bindSingletonPresenterWidget(ErrorDialogPresenterWidget.class,
                                     ErrorDialogPresenterWidget.MyView.class, ErrorDialogPopupView.class);

        // Error Page
        bindPresenter(ErrorPagePresenter.class, ErrorPagePresenter.MyView.class,
                      ErrorPageView.class, ErrorPagePresenter.MyProxy.class);

        // Sales
        bindPresenter(ActivitiesPresenter.class, ActivitiesPresenter.MyView.class,
                      ActivitiesView.class, ActivitiesPresenter.MyProxy.class);
        bindPresenter(CalendarPresenter.class, CalendarPresenter.MyView.class,
                      CalendarView.class, CalendarPresenter.MyProxy.class);
        bindPresenter(AccountsPresenter.class, AccountsPresenter.MyView.class,
                      AccountsView.class, AccountsPresenter.MyProxy.class);

        // Settings
        bindPresenter(AdministrationPresenter.class, AdministrationPresenter.MyView.class,
                      AdministrationView.class, AdministrationPresenter.MyProxy.class);

        // Resource Centre
        bindPresenter(HighlightsPresenter.class, HighlightsPresenter.MyView.class,
                      HighlightsView.class, HighlightsPresenter.MyProxy.class);
    }
}
